Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow new format for local_key #418

Merged
merged 3 commits into from
Jan 15, 2024
Merged

Allow new format for local_key #418

merged 3 commits into from
Jan 15, 2024

Conversation

justerror
Copy link
Contributor

@justerror justerror commented Jul 6, 2023

Allow latin alphanumeric and special character for local_key
Remove local_key check

Fixes #409
Fixes #410

index.js Outdated Show resolved Hide resolved
Copy link

@ascl00 ascl00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me (FWIW).

@hosigi05
Copy link

Experience the new format not being allowed in the current version of this plugin too. Would be great this could be fixed in due course. Thanks @iRayanKhan

@SoCuul
Copy link

SoCuul commented Sep 4, 2023

As I just discovered, this regex does not cover all local keys. One of my local keys failed the regex parsing, specifically it included a | character.

I modified the regex string a little, and it looks like this fixes the problem:

^[a-zA-Z0-9~`!@#$%^&*|()+={}\[\];:\'\"<>.,\/\\\?-_]+$

@ascl00
Copy link

ascl00 commented Sep 4, 2023

At this point it might be just better to remove this check. It seems pretty much any ASCII character can be in the key, so continuing to extend the regex is not really helping.

@houmark
Copy link

houmark commented Sep 8, 2023

+1 for merging this. I also encountered a new local key format today with both uppercase chars and special chars as well.

index.js Outdated Show resolved Hide resolved
@justerror
Copy link
Contributor Author

Removed all checks for local_key due to variability.

@hosigi05
Copy link

Getting this error when installing this update in my environment:

[9/15/2023, 9:35:56 AM] ====================
[9/15/2023, 9:35:56 AM] ERROR LOADING PLUGIN homebridge-tuya:
[9/15/2023, 9:35:56 AM] /var/lib/homebridge/node_modules/homebridge-tuya/lib/AirConditionerAccessory.js:432
            this.setMultiState({this.dpActive: true, this.dpRotationSpeed: this.convertRotationSpeedFromHomeKitToTuya(value)}, callback);

SyntaxError: Unexpected token '.'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/var/lib/homebridge/node_modules/homebridge-tuya/index.js:11:33)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
[9/15/2023, 9:35:56 AM] ====================

@lostdriveway
Copy link

Hi - new here and excuse my noobness - having this issue with my Arlec ceiling fan - how do you install this fix?

@SoCuul
Copy link

SoCuul commented Sep 15, 2023

Hi - new here and excuse my noobness - having this issue with my Arlec ceiling fan - how do you install this fix?

Hey! Since this isn't merged into the project yet, it'll make it harder to install.
What you can try is replacing a few lines in your currently installed version.
Keep in mind, all of these files will be located inside the homebridge-tuya folder inside node_modules.

File 1: index.js

Replace this:

if (!/^[0-9a-f]+$/i.test(device.key)) return this.log.error('%s, key for %s (%s), is not a valid key.', device.key.replace(/.{4}$/, '****'), device.name || 'unnamed device', device.id);

With this:

if (!/^[a-zA-Z0-9~`!@#$%^&*|()+={}\[\];:\'\"<>.,\/\\\?-_]+$/i.test(device.key)) return this.log.error('%s, key for %s (%s), is not a valid key.', device.key.replace(/.{4}$/, '****'), device.name || 'unnamed device', device.id)

File 2: cli-decode.js

Replace this:

if (!/^[0-9a-f]+$/i.test(key)) {

With this:

if (!/^[a-zA-Z0-9~`!@#$%^&*|()+={}\[\];:\'\"<>.,\/\\\?-_]+$/i.test(key)) {

This may not work (in the future), but it's the easiest solution for you right now. It definitely solved it for me :)

@lostdriveway
Copy link

Awesome thanks for that! - now again excuse my basic skills

"Keep in mind, all of these files will be located inside the homebridge-tuya folder inside node_modules."

where is the node_modules folder usually found?

@SoCuul
Copy link

SoCuul commented Sep 15, 2023

Awesome thanks for that! - now again excuse my basic skills

"Keep in mind, all of these files will be located inside the homebridge-tuya folder inside node_modules."

where is the node_modules folder usually found?

If you're running homebridge on docker, you can find it by entering your container, by running these commands:

docker exec -it homebridge /bin/bash
cd homebridge/node_modules/homebridge-tuya

If you're running it without any complicated setup, just go into the homebridge folder, then you'll see node_modules, enter that and you'll see tuya-homebridge.

Hope that clarifies it a bit, but feel free to let me know if you need any help!

@lostdriveway
Copy link

Thanks I'll give it a crack when I get home from work this afternoon!

@lostdriveway
Copy link

Ok I can get this far- but no idea what the command is to edit the 2 files...sorry

homebridge

@SoCuul
Copy link

SoCuul commented Sep 16, 2023

Ok I can get this far- but no idea what the command is to edit the 2 files...sorry

homebridge

From there, you can edit it with any text editor of your choice. I suggest using nano, which you can find tutorials for online!

@lostdriveway
Copy link

ok - did the first file - can't find the cli-decode.js file though?

@SoCuul
Copy link

SoCuul commented Sep 16, 2023

ok - did the first file - can't find the cli-decode.js file though?

cli-decode.js should be located in the bin folder

@michael-j-green
Copy link

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?

This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

@iRayanKhan
Copy link
Owner

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?

This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

@lostdriveway
Copy link

Well I managed to find and make the requested changes to the code - no local key error message after reboot but it still can't find the device.

I'll put it in the too hard basket for now until there's a better fix.

@SoCuul
Copy link

SoCuul commented Sep 17, 2023

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?
This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

@iRayanKhan is there a chance you could merge this into the master branch and publish it.
This plugin is still fully functional and works as intended, but this single local_key change pretty much makes the entire thing unusable.

@michael-j-green
Copy link

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?
This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

Good question... I sadly don't have an answer for you. I'm not knowledgable enough with Homebridge or the inner workings of this plugin to take it on myself.

Perhaps one of the more active fork maintainers, or one of the more knowledgable users in this PR like @SoCuul (assuming they want to take it on)?

@SoCuul
Copy link

SoCuul commented Sep 17, 2023

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?

This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

Good question... I sadly don't have an answer for you. I'm not knowledgable enough with Homebridge or the inner workings of this plugin to take it on myself.

Perhaps one of the more active fork maintainers, or one of the more knowledgable users in this PR like @SoCuul (assuming they want to take it on)?

I would be happy to help out, but while I'm fluent in typescript, I have little to no experience building a homebridge plug-in. I've gone over the documentation countless times, but I haven't fully got the grasp of it.

@lostdriveway
Copy link

Finally got it working thanks to some help in the discord

had to add "//" in front of line 99 on the index.js and also added a line into the config.json and it finally showed up in Homebridge

@michael-j-green
Copy link

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?

This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

Good question... I sadly don't have an answer for you. I'm not knowledgable enough with Homebridge or the inner workings of this plugin to take it on myself.
Perhaps one of the more active fork maintainers, or one of the more knowledgable users in this PR like @SoCuul (assuming they want to take it on)?

I would be happy to help out, but while I'm fluent in typescript, I have little to no experience building a homebridge plug-in. I've gone over the documentation countless times, but I haven't fully got the grasp of it.

That's fair :) Sorry to call you out like that!

@ayushsharma82
Copy link

A working fork till then for easy install: https://github.com/ayushsharma82/homebridge-tuya-local

@iRayanKhan Feel free to pull and merge.

@05TEVE
Copy link
Collaborator

05TEVE commented Jan 9, 2024

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?

This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

Good question... I sadly don't have an answer for you. I'm not knowledgable enough with Homebridge or the inner workings of this plugin to take it on myself.
Perhaps one of the more active fork maintainers, or one of the more knowledgable users in this PR like @SoCuul (assuming they want to take it on)?

I would be happy to help out, but while I'm fluent in typescript, I have little to no experience building a homebridge plug-in. I've gone over the documentation countless times, but I haven't fully got the grasp of it.

That's fair :) Sorry to call you out like that!

I am happy to help out and try keep this plugin alive. I messaged @iRayanKhan a while back on twitter but never

Likely not the place to ask this, but is there a fork of this plugin that's actually being maintained?
This repo has 21 PR's, and 99 issues, and the maintainer appears to be MIA. I asked back in February if the maintainer was able to add another admin to the project to allow PR's to be merged, and releases to be made - crickets.

Is there a mystery admin who is willing to take care of it? Someone did message me on Twitter then I didn't hear further.

That was me that reached out. I have sent a request to add you on Discord to discuss further.

@05TEVE
Copy link
Collaborator

05TEVE commented Jan 10, 2024

A working fork till then for easy install: https://github.com/ayushsharma82/homebridge-tuya-local

@iRayanKhan Feel free to pull and merge.

A working fork till then for easy install: https://github.com/ayushsharma82/homebridge-tuya-local

@iRayanKhan Feel free to pull and merge.

Hey @ayushsharma82, I have spoken with @iRayanKhan and got access to merge PRs into the repository with the intention to start fixing some of the issues listed. Looking at the changes you have made i am thinking it might make sense to start with merging your fork back and publishing a new version?

Copy link
Collaborator

@05TEVE 05TEVE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me.

@05TEVE 05TEVE merged commit f503e93 into iRayanKhan:main Jan 15, 2024
@05TEVE
Copy link
Collaborator

05TEVE commented Jan 15, 2024

Changes have been published up to NPM as version 3.1.0-beta.2. Should be available for testing on homebridge.

ThisIsQasim pushed a commit to ThisIsQasim/homebridge-tuya that referenced this pull request May 3, 2024
* allow new format for local_key

* fixup! allow new format for local_key

* remove all checks for local_key
ThisIsQasim pushed a commit to ThisIsQasim/homebridge-tuya that referenced this pull request May 3, 2024
* allow new format for local_key

* fixup! allow new format for local_key

* remove all checks for local_key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tuya local keys no longer work and have changed format? Not a valid local key